#include <stdio.h>
#include <SDL2/SDL.h>

int main(int argc, char *argv[])
{
	int running = 1;
	int x=0,y=0;
	SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
	SDL_Window *window = SDL_CreateWindow("fuck", SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_OPENGL);
	SDL_Renderer *render = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
	SDL_Rect r;
	SDL_Event e;
	r.x = 800/2;
	r.y = 600/2;
	r.h = 50;
	r.w = 50;

	while(running)
		{
			while(SDL_PollEvent(&e))
				{
					switch(e.type)
						{
						case SDL_QUIT:
							running = 0;
							break;
						case SDL_KEYDOWN:
							if(e.key.keysym.scancode == SDL_SCANCODE_LEFT)
								x = -5;
							else if(e.key.keysym.scancode == SDL_SCANCODE_RIGHT)
								x = 5;
							else if(e.key.keysym.scancode == SDL_SCANCODE_UP)
								y = -5;
							else if(e.key.keysym.scancode == SDL_SCANCODE_DOWN)
								y = 5;
							break;
						case SDL_KEYUP:
							if((e.key.keysym.scancode == SDL_SCANCODE_LEFT) || (e.key.keysym.scancode == SDL_SCANCODE_RIGHT))
								x = 0;
							else if((e.key.keysym.scancode == SDL_SCANCODE_UP) || (e.key.keysym.scancode == SDL_SCANCODE_DOWN))
								y= 0;
							break;
						}
				}
			SDL_SetRenderDrawColor(render, 0, 0, 0, 0);
			SDL_RenderClear(render);
			SDL_SetRenderDrawColor(render, 0, 0, 255, 0);
			SDL_RenderDrawRect(render, &r);
			SDL_RenderPresent(render);
			r.x+=x;
			r.y+=y;

			SDL_Delay(1000/60);
		}
	SDL_DestroyRenderer(render);
	SDL_DestroyWindow(window);

	SDL_Quit();


	return 0;
}
